package com.qriver.session.config;

import com.qriver.session.interceptor.CookieTokenInterceptor;
import com.qriver.session.interceptor.UserTokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

//注册拦截器
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {


    @Bean
    public UserTokenInterceptor userTokenInterceptor() {
        return new UserTokenInterceptor();
    }

    @Bean
    public CookieTokenInterceptor cookieTokenInterceptor() {
        return new CookieTokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自己的拦截器并设置拦截的请求路径
        registry.addInterceptor(cookieTokenInterceptor())
                .addPathPatterns("/index","/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
